<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- https://blog.csdn.net/gty931008/article/details/104463371 -->
  <!-- https://blog.csdn.net/gty931008/article/details/104469015 -->
</head>

<body>

</body>
<script>
  "use strict"; {
    function combination(arr, m) {
      let r = [];
      _([], arr, m);
      return r;
      function _(t, a, m) {
        //t:临时数组 a:目标数组 m：多少个数进行组合
        if (m === 0) {
          r[r.length] = t;//相当于push
          return;
        }
        for (let i = 0; i <= a.length - m; i++) {
          //从0开始 到n-m
          let b = t.slice();//将t赋值给b 不能用=赋值，使用slice会形成新的数组赋值
          b.push(a[i])
          _(b, a.slice(i + 1), m - 1);
        }
      }
    };
  };
</script>

</html>